#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

// static int get_char( bool undo = false);
static int g_indent = 0;
static inline void increase_indent() { ++g_indent; }
static inline void decrease_indent() { --g_indent; }
static void print_indent( void );
static void print_newline( void );
static void print_char( int c );
static void fmtjson( int c );

int main( int argc, char *argv[] )
{
	int c = 0;
	while( (c = getchar() ) != EOF ) {
		fmtjson( c );
	}
	print_newline();
}

static void print_indent( void )
{
	for( int i = 0; i < g_indent; i++ )
		printf( "    " );
}

static void print_newline( void )
{
	print_char( '\n' );
}

static void print_char( int c )
{
	static int g_last_char = '\n';
	if( '\n' == g_last_char ) {
		if( '\n' == c )
			return;
		print_indent();
	}
	putchar( c );
	g_last_char = c;
}

/*
static int get_char( bool undo )
{
	static bool g_undo_flag = false;
	static int g_cur_char = EOF;

	if( undo ) {
		g_undo_flag = true;
		return g_cur_char;
	}

	if( g_undo_flag ) {
		g_undo_flag = false;
		return g_cur_char;
	}
	else {
		return g_cur_char = getchar();
	}
}
*/

static void fmtjson( int c )
{
	static int g_last_char = '\0';
	static bool g_in_string = false;
	static bool g_in_escape = false;

	if( g_in_string ) {
		if( g_in_escape ) {
			g_in_escape = false;
		}
		else {
			switch( c ) {
			case '\\':
				g_in_escape = true;
				break;
			case '"':
				g_in_string = false;
				break;
			}
		}
		print_char( c );
	}
	else {
		switch( c ) {
		case '"':
			g_in_string = true;
			print_char( c );
			break;
		case '[':
		case '{':
			print_newline();
			print_char( c );
			increase_indent();
			print_newline();
			break;
		case ']':
		case '}':
			print_newline();
			decrease_indent();
			print_char( c );
			/*
			int next;
			while( ( next = get_char() ) != EOF && isspace( next ) );
			if( ',' != next )
				print_newline();
			get_char( true );
			*/
			break;
		case ',':
			print_char( c );
			print_newline();
			break;
		default:
			if( !isspace( c ) )
				print_char( c );
		}
	}
	g_last_char = c;
}

